/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pessoas.presenter.apoio;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import pessoas.model.Pessoa;

/**
 *
 * @author jakson
 */
public class OperacaoArquivo {

    public void SalvarTxt(File arquivo, Pessoa p) throws IOException {
        FileWriter w = new FileWriter(arquivo, true);
        BufferedWriter bf = new BufferedWriter(w);
        bf.write(p.toString());
        bf.newLine();
        bf.close();
    }

   public void adicionaTxt(Collection<Pessoa> p, String caminho) throws IOException {
        File arquivoTxt = new File(caminho);
        FileWriter we = new FileWriter(arquivoTxt, true);
        BufferedWriter bfe = new BufferedWriter(we);

        Iterator<Pessoa> it = p.iterator();
        while (it.hasNext()) {
            Pessoa pe = it.next();
            bfe.write(pe.toString());
            bfe.newLine();
        }

        bfe.close();
    }


    public void limparArquivo(File caminho) throws IOException {
        BufferedWriter clean = new BufferedWriter(new FileWriter(caminho));
        clean.close();

    }

}
